﻿using Network.General;
using Network.General.Server;
using Network.IPCWork;
using Network.Server;

namespace Server
{
    public class ZoneServer : ServerModule
    {
        private NetManager _net;
        private IPCManager _ipc;
        private ServerContext _context;

        public ZoneServer(int id, int port) : base()
        {
            this.id = id;
            this.port = port;
        }

        public override void Start()
        {
            _net = new NetManager();
            _net.Init(ConnectionType.UDP, port);

            _ipc = new IPCManager();
            _ipc.Init(id, port + 1);

            _context = new ServerContext();
            _context.net = _net;
            _context.ipc = _ipc;

            // 业务逻辑初始化
            OnlineManager.Instance.Init(_context);
            RoomManager.Instance.Init(_context);

            base.Start();
        }

        public override void Stop()
        {
            if (_net != null)
            {
                _net.Clean();
                _net = null;
            }
            if (_ipc != null)
            {
                _ipc.Clean();
                _ipc = null;
            }
        }

        public override void Tick()
        {
            _net.Tick();
            _ipc.Tick();
        }
    }
}